package com.jinliang.think.tools;

import org.junit.Test;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

public class ReflectUtils {

    @Test
    public void tt() throws IllegalAccessException {
        Student student = new Student();
        student.sex="1";
        student.setAge("12");
        student.setName("liujinliang");
        student.setAddress("shanghai");
        //反射获取所有属性

        Class<? extends Student> aClass = student.getClass();
        Field[] fields = aClass.getFields();
        Field[] declaredFields = aClass.getDeclaredFields();
        for (Field field : declaredFields) {
            field.setAccessible(true);
            field.get(student);

            System.out.println(field.get(student));
            field.set(student,"333");
        }

        Method[] declaredMethods = aClass.getDeclaredMethods();


    }
}
